#include <iostream>
#include <string>
#include <string.h>
using namespace std;

int numDistinct(string s, string t) {
    int m = s.size();
    int n = t.size();
    if (n > m) return 0;
    int dp[m+1][n+1];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= m; i++)
        dp[i][0] = 1;
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (t[j-1] == s[i-1]) {
                dp[i][j] = dp[i-1][j-1] + dp[i-1][j];
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }

    return dp[m][n];
}
int main(){
    string s = "carrotr";
    string t = "car";
    cout << numDistinct(s, t) << endl;
    return 0;
}